package rs.pnv.model.payment;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.hibernate.validator.constraints.NotBlank;

import rs.pnv.model.AbstractEntity;

@Entity
@Table(name = "SEP_MERCHANT")
@XmlAccessorType(XmlAccessType.FIELD)
public class Merchant extends AbstractEntity {

	@NotBlank
	@Column(nullable = false)
	@XmlElement(nillable = false)
	private String merchantId;

	@NotBlank
	@Column(nullable = false)
	@XmlElement(nillable = false)
	private String merchantPassword;

	@OneToOne(optional = true)
	private PaymentUrlRequest paymentUrlRequest;

	public Merchant() {

	}

	public String getMerchantId() {
		return merchantId;
	}

	public void setMerchantId(String merchantId) {
		this.merchantId = merchantId;
	}

	public String getMerchantPassword() {
		return merchantPassword;
	}

	public void setMerchantPassword(String merchantPassword) {
		this.merchantPassword = merchantPassword;
	}

	public PaymentUrlRequest getPaymentUrlRequest() {
		return paymentUrlRequest;
	}

	public void setPaymentUrlRequest(PaymentUrlRequest paymentUrlRequest) {
		this.paymentUrlRequest = paymentUrlRequest;
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder()
				.append(merchantId)
				.append(merchantPassword)
				.appendSuper(super.hashCode())
				.hashCode();
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}
		if (obj == this) {
			return true;
		}
		if (obj.getClass() != getClass()) {
			return false;
		}

		final Merchant otherMerchant = (Merchant) obj;

		return new EqualsBuilder()
				.append(merchantId, otherMerchant.getMerchantId())
				.append(merchantPassword, otherMerchant.getMerchantPassword())
				.appendSuper(super.equals(obj))
				.isEquals();
	}

	@Override
	public String toString() {
		return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
				.append("merchantId", merchantId)
				.append("merchantPassword", merchantPassword)
				.append(super.toString())
				.toString();
	}

}
